<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
    	<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
		<title></title>
		<link rel="stylesheet" href="toastr/toastr.min.css">


	</head>
	<style>

		#logright{
			height: 540px;
			width: 300px;
			background-image: url(img/logback.jpg);
			background-size:300px 540px;
			background-repeat:no-repeat;
			text-align: center;
			padding-top: 100px;
			color: white;
		}
		.row{
			text-align: center;
			color: black;
		}

	</style>
	<body style="background-color:lightgray;">
	<div style="width:980px ; height: 540px; background-color: white;margin:auto; margin-top: 100px; ">
		<div class="container">
			<div class="row">
				<div class="col-md-5" style="margin-top: 80px;padding-left: 170px;">
						<h3 style="font-weight:bold;";>欢迎来到恒源世家</h3><br />
						<div class="form-group">
							<label for="u_name">用户名</label>
							<input type="text" class="form-control" id="u_name" placeholder="请输入用户名">
						</div>
						<div class="form-group">
							<label for="u_pwd">密码</label>
							<input type="password" class="form-control" id="u_pwd" name="u_pwd" placeholder="请输入密码" data-toggle="u_pwd">

						</div>
						<div class="col-md-6">
							<div class="checkbox" style="text-align: left;">
								<label>
									<input name="nologin" type="checkbox" value="1" id="nologin"> 下次免密登陆
								</label>
							</div>
						</div>
						<div class="col-md-6" style="margin-top: 10px;padding-left: 10px">
							<a href="#" id="forgetPwd">忘记密码?</a>
						</div>
						<div class="col-md-12">
							<div id="errorlog" class="hidden" style="color: red;font-weight: bold; text-align: center"></div>
						</div>
						<div class="col-md-12">
							<button type="submit"  id="logform" class="btn btn-default" style="background-color:cornflowerblue; color: white;">登陆</button>
						</div>
					<!--忘记密码的模态框-->
						<div class="modal fade" id="ModalForPwd" tabindex="-1" role="dialog"
							 aria-labelledby="myModalLabel" aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
											&times;
										</button>
										<h4 class="modal-title" id="myModalLabel">
											忘记密码
										</h4>
									</div>
									<div class="modal-body" id="TipForPwd">
										<div class="form-group">
											<label for="uInfo_name">用户名</label>
											<input type="text" class="form-control" id="uInfo_name" name="uInfo_name" placeholder="请输入用户名">
										</div>
										<div class="form-group">
											<label for="uInfo_phone">电话</label>
											<input type="text" class="form-control" id="uInfo_phone" name="uInfo_phone" placeholder="请输入您的电话号码">

										</div>
										<div class="form-group">
											<label for="uInfo_pwd">新密码</label>
											<input type="text" class="form-control" id="uInfo_pwd" name="uInfo_pwd" placeholder="请输入您的新密码">
										</div>
									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-default"
												data-dismiss="modal">关闭            </button>
										<button type="button" class="btn btn-primary" id="ComfirmForPwd">
											提交更改
										</button>
									</div>
								</div><!-- /.modal-content --></div>
						</div>

				</div>
				<div class="col-md-3 col-md-offset-2" id="logright" >
					<h3>还未注册?</h3><br />
					<h5>立即注册发现大量机会!</h5><br /><br /><br /><br />

					<img src="img/button1.png" width="60" height="60" alt="注册" class="img-circle">
				</div>
			</div>
		</div>





	</div>
		<script src="jquery/jquery-3.4.1.min.js"></script>
		<script src="bootstrap/js/bootstrap.js"></script>
		<script src="bootstrap/bootstrap-show-password-1.2.0/dist/bootstrap-show-password.min.js"></script>
		<script src="jquery-validation/jquery.validate.js"></script>
		<script src="jquery-validation/messages_zh.js"></script>
		<script src="toastr/toastr.min.js"></script>


	<script>
        $(document).ready(function(){

//登陆后过期清除登陆信息
            if(localStorage.getItem("u_name")!=null ||"" &&localStorage.getItem("u_pwd")!=null||""){
                var exp = 1000 * 60 * 60 *24 ;//过期时间为1小时1000 * 60 * 60
                //获取本地值
                let item_name = localStorage.getItem("u_name");
                let item_pwd = localStorage.getItem("u_pwd");
                // (当前时间 - 存储的元素在创建时候设置的时间) > 过期时间
                var time= localStorage.getItem("curtime");
                var  isTimed=(new Date().getTime()-time) >exp;
                if(isTimed){
                    //过期了
                    localStorage.removeItem("u_name");
                    localStorage.removeItem("u_pwd");
                    $("#errorlog").text("您的免密登陆已过期!");
                }else{
                    //没过期
                    //把存储的登陆信息显示在input里
                    $("#u_name").val(item_name);
                    $("#u_pwd").val(item_pwd);
                }


            }



            $("#nologin").click(function () {// $("#nologin").get(0).checked  被选中
                //选择了免登陆----登陆信息存在本地,并设置时间
                localStorage.setItem("u_name",$("#u_name").val());
                localStorage.setItem("u_pwd",$("#u_pwd").val());
                var curtime = new Date().getTime(); //获取当前时间
                localStorage.setItem("curtime",curtime);
            });




            $("#logform").click(function () {
                $.ajax({
                    type:"post",
                    url:"user/index",
                    async:true,
                    dataType:"json",
                    data:{
                        u_name:$("#u_name").val(),
                        u_pwd:$("#u_pwd").val()

                    },
                    success:function(rs){
                        var errorCode = rs.errorCode;
                        if (errorCode==0){
                            $(location).attr("href","gotoroomIndex");
                        } else if(errorCode==1){
                            $(location).attr("href","gotoroomIndex2");
                        }else{
                            var msg = rs.status;
                            $("#errorlog").text(msg);
                            $("#errorlog").removeClass("hidden");

                        }

                    },
                    error:function(XMLHttpRequest, textStatus, errorThrown){
                        this;
                    }
                });
            });





//注册跳转
            $(".img-circle").click(function () {
                $(location).attr("href","gotoregister");
            });
//密码的显示隐藏
            $("#u_pwd").password({
                eyeClass: 'glyphicon',
                eyeOpenClass: 'glyphicon-eye-open',
                eyeCloseClass: 'glyphicon-eye-close'
            });


            $("#forgetPwd").click(function () {
                $("#ModalForPwd").modal("show");

            });



            $("#ComfirmForPwd").click(function () {
                $.ajax({
                    type:"post",
                    url:"user/forgetpwd",
                    async:true,
                    dataType:"json",
                    data:{
                        uInfo_name:$("#uInfo_name").val(),
                        uInfo_pwd:$("#uInfo_pwd").val(),
                        uInfo_phone:$("#uInfo_phone").val()

                    },
                    success:function(rs){
                        var errorCode = rs.errorCode;
                        var msg=rs.status;
                        if (errorCode==0){
                            $("#ModalForPwd").modal("hide");
                            toastr.success(rs.status);
                        } else{
                            $("#ModalForPwd").modal("hide");

                            toastr.error(rs.status);

                        }
                        console.info("errorCode"+errorCode)

                    },
                    error:function(XMLHttpRequest, textStatus, errorThrown){
                        this;
                    }
                });
            });


        });

	</script>
	</body>
	
</html>
